/**
 * Created by IntelliJ IDEA.
 * User: Bezdelnick
 * Date: 13.09.12
 * Time: 16:08
 * To change this template use File | Settings | File Templates.
 */
package fgui.control {
import fgui.GuiComponent;

import fgui.IAnimationComponent;

import flash.events.MouseEvent;
import flash.geom.Point;

import mx.core.UIComponent;

public class DrawButton extends GuiComponent implements IAnimationComponent {
    private var _canvas:UIComponent = new UIComponent();

    public function DrawButton(coordinate:Point, size:Point) {
        super(coordinate, size);

        renderColor = 0xaaaaaa;
        renderAlpha = 1;
        renderDefault();

        addChild(_canvas);

        addEventListener(MouseEvent.MOUSE_OVER, renderOnMouseOver);
        addEventListener(MouseEvent.MOUSE_DOWN, renderOnMouseDown);
        addEventListener(MouseEvent.MOUSE_OUT, renderOnMouseOut);
    }

    override public function renderDefault():void {
        this.drawRoundedRectangle(renderColor, renderAlpha, new Point(), this.getSize(), new Point(15, 15));
    }

    private var differenceColor:uint = 0x222222;
    public function renderOnMouseOver(event:MouseEvent):void {
        renderCustom(renderColor - differenceColor);
    }

    public function renderOnMouseDown(event:MouseEvent):void {
        renderCustom(renderColor - 2*differenceColor);
    }

    public function renderOnMouseOut(event:MouseEvent):void {
        renderDefault();
    }


    public function get canvas():UIComponent {
        return _canvas;
    }
}
}
